package com.sfc.spiderweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sfc.spiderweb.entity.param.AmazonTransferParam;
import com.sfc.spiderweb.entity.po.AmazonTransfer;
import com.sfc.spiderweb.mapper.AmazonTransferMapper;
import com.sfc.spiderweb.service.AmazonTransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AmazonTransferServiceImpl extends ServiceImpl<AmazonTransferMapper, AmazonTransfer> implements AmazonTransferService {

    @Autowired
    private AmazonTransferMapper mapper;

    @Override
    public Page<AmazonTransfer> getPage(AmazonTransferParam param) {
        Page<AmazonTransfer> page = new Page<>(param.getCurrent(), param.getSize());
        QueryWrapper<AmazonTransfer> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(param.getAccount())) {
            wrapper.lambda().eq(AmazonTransfer::getAccount, param.getAccount());
        }
        if (!StringUtils.isEmpty(param.getStartTransferDate())) {
            wrapper.lambda().ge(AmazonTransfer::getTransferDate, param.getStartTransferDate());
        }
        if (!StringUtils.isEmpty(param.getEndTransferDate())) {
            wrapper.lambda().le(AmazonTransfer::getTransferDate, param.getEndTransferDate());
        }
        wrapper.lambda().eq(AmazonTransfer::getStatus, "1");
        Page<AmazonTransfer> amazonTransferPage = mapper.selectPage(page, wrapper);
        return amazonTransferPage;
    }
}
